<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>详情页</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        header {
            height: 50px;
            width: auto;
            background-color: rgb(241, 180, 66);
            color: #fff;
            font-size: 25px;
            text-align: center;
            line-height: 50px;
        }

        #newBtn {
            position: fixed;
            width: 50px;
            height: 50px;
            left: 50%;
            top: 50%;
            margin-left: -25px;
            margin-top: -25px;
            border: 1px solid #ccc;
            border-radius: 8px;
            font-size: 18px;
            text-align: center;
            line-height: 50px;
            box-shadow: 0px 3px 7px 2px #ccc;
            color: black;
        }

        a {
            text-decoration: none;
        }

        ul>li {
            border: 1px solid #000;
            height: 50px;
            margin-bottom: 5px;
            line-height: 50px;
            box-shadow: 0px 3px 7px 2px #ccc;
            padding-left: 20px;
            position: relative;
        }

        button {
            height: 30px;
            color: red;
        }
    </style>
</head>

<body>
    <header>详情页</header>
    <main>
        <ul id="list">
            <li>内容</li>
        </ul>
        <button id="del">删除</button>
        <button id="Alldel">删除全部</button>
    </main>
    <footer><a id="newBtn" href="../index.html">主页</a></footer>
    <script>
        let ul = document.getElementById('list')
        let Alldel = document.getElementById('Alldel')
        for (var i = 0, len = localStorage.length; i < len; ++i) {
            lis = `标题为:${localStorage.getItem(localStorage.key(i)).split(',')[0]},内容为:${localStorage.getItem(localStorage.key(i)).split(',')[1]}`
            console.log(lis);
            // 1.创建节点元素节点
            let li = document.createElement('li')
            // 2.添加节点node.appendChild(child) node父级 child是子级 后面追加元素 类似于数组中数组中push
            ul.appendChild(li)
            li.innerText = lis
        }
        let del = document.getElementById('del')
        del.onclick = function () {
            localStorage.removeItem(localStorage.key(localStorage.length - 1))
            location.reload();
        }
        Alldel.onclick = function () {
            localStorage.clear()
            location.reload();
        }
    </script>
</body>

</html>